<template>
	<view class="dropdown">
		<view class="item" v-for="(item,index) in dropItem" :key="item.id" @click="dropClick(item,index)">
			<text>{{item.title}}</text> <u-icon :name="item.title==title?'arrow-up':'arrow-down'"
				color="#c8c9cc"></u-icon>

		</view>

		<!-- <view class="dropdown_mask"></view> -->
		<view class="dowMsk" :style="{height:status1?'270rpx':'0rpx'}">
			<scroll-view scroll-y="true" style="height: 270rpx">
				<u-cell-group>
					<u-cell :title="ite.title" v-for="ite in selectOptions" :key="ite.id" :isLink="false"
						@click="fenleiClick(ite)">
						<text slot="value" class="u-slot-value">
							<text v-if="ite.title==dropItem[index].title">
								√
							</text>
						</text>
					</u-cell>
				</u-cell-group>
			</scroll-view>

		</view>
	</view>
</template>

<script>
	export default {
		name: "dropdown",
		data() {
			return {
				status1: false,
				optionsList: [],
				title: '',
				id: '',
				index: 10,
				selectOptions: [],
				dropItem: [{
						id: 1,
						selectId: '',
						title: '全部分类',
						options: [
						]
					},
					{
						id: 2,
						title: '默认排序',
						options: [
							{
								id: 1,
								title: '默认排序'
							},
							{
								id: 2,
								title: '离我最近'
							},
							
						]
					},
					{
						id: 3,
						title: '筛选',
						options: [{
								id: 1,
								title: '正在营业'
							},
							{
								id: 0,
								title: '暂停营业'
							},
							
						]
					}
				]
			};
		},
		mounted() {
				this.$req('GET',this.$api.fenLlist,{}).then(res =>{
					
					// this.lists = res.data.list.map(item => ({ name: item.title }));
					let lists = res.data.list.map((item)=>{
						return {
							id:item.id,
							title:item.title
						}
					})
					this.$set(this.dropItem[0],"options",lists)
					
				})
			
		},
		methods: {
			dropClick(item, index) {
				this.selectOptions = item.options
				this.id = item.id
				if (index == this.index) {
					this.status1 = !this.status1
				} else {
					this.status1 = true
				}
				this.index = index

			},
			selectOption(option, data) {
				console.log(data);
				this.status = data.status
				this.title = data.title
				this.optionsList = option
			},
			fenleiClick(item) {
				this.$set(this.dropItem[this.index], "title", item.title)
				this.status1 = false
				// this.$emit('tabClick', `我选择的是${item.title}`)
				this.$emit('tabClick', {
				  text: `我选择的是${item.title}`,
				  id: this.id,
				  item_id:item.id
				});
				console.log(item,'查看这个item是什么')
				
				uni.setStorageSync('fenlei',item.id)
				uni.setStorageSync('fenleiTitle',item.title)
				
			}
		}
	}
</script>

<style scoped lang="scss">
	.u-slot-value {
		color: #ff9900;
	}

	.item {
		display: flex;
		align-items: center;

		text {
			padding-right: 8rpx;
			font-size: 26rpx;
		}
	}

	.dowMsk {
		position: absolute;
		background-color: #fff;
		top: 50rpx;
		left: 0rpx;
		width: 100%;
		z-index: 999;
		overflow: hidden;
		transition: all .3s linear;
	}

	.dropdown {
		display: flex;
		justify-content: space-between;
		margin: 15rpx 0;
		padding: 0 50rpx;
		position: relative;

		&__mask {
			position: absolute;
			z-index: 9;
			background: rgba(0, 0, 0, .3);
			width: 100%;
			left: 0;
			top: 0;
			bottom: 0;
		}

	}

	.dowMsk {
		position: absolute;
		background-color: #fff;
		top: 50rpx;
		left: 0rpx;
		width: 100%;
		z-index: 999;
		overflow: hidden;
		transition: all .3s linear;
	}
</style>